package com.bwf.obj;

import java.io.*;

/**
 * @Version v1.0
 * @Description: TODO
 * @Author ZHANZHONGXIN
 * @Date 2022/5/18 10:00
 * @Copyright 博为峰
 */
public class ObjectStreamDemo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
//        write();
        read();
    }

    private static void read() throws IOException, ClassNotFoundException {
        final FileInputStream fileInputStream = new FileInputStream("obj.txt");
        final ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream);
        final Student student = (Student)objectInputStream.readObject();
        System.out.println(student);
    }

    private static void write() throws IOException {
        final FileOutputStream fileOutputStream = new FileOutputStream("obj.txt");
        final ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream);
        final Student student = new Student("张三", 20, "男");
        objectOutputStream.writeObject(student);
    }
}
